<!-- 城市合伙人 -->
<template>
	<section>
		<!--工具条-->
		<el-col :span="24" class="toolbar">
			<div style="display: flex;align-items: center;justify-content: space-between;height: 40px;">
				<el-link type="danger" disabled>提示:手续费和打赏费一天只可修改一次</el-link>
				<el-form :inline="true" :model="filters" style="margin-top: 12px;">
					<el-form-item>
						<el-input v-model="filters.text" placeholder="请输入期数"></el-input>
					</el-form-item>
					<el-form-item >
						<el-button type="primary" icon="el-icon-search" v-on:click="getUsersList(1)">查询</el-button>
					</el-form-item>
				</el-form>
			</div>
		</el-col>
		<!--列表-->
		<el-table :data="UserList" highlight-current-row v-loading="loading" border :cell-style="cellStyle" :header-cell-style="rowClass" style="width: 100%;">
			<el-table-column type="index" align="center" label="ID" width="80">
			</el-table-column>
			<el-table-column prop="name" align="center" label="姓名">
			</el-table-column>
			<el-table-column prop="phone" align="center" label="手机号">
			</el-table-column>
			<el-table-column prop="province" align="center" label="所在省" width="120">
			</el-table-column>
			<el-table-column prop="city" align="center" label="所在市" width="120">
			</el-table-column>
			<el-table-column prop="commissionMoney" align="center" label="手续费" width="120">
				<template slot-scope="scope">
					<p v-if="scope.row.isInput == '0'">--</p>
					<p v-else >{{scope.row.commissionMoney}}</p>
				</template>
			</el-table-column>
			<el-table-column prop="tipMoney" align="center" label="打赏费" width="120" >
				<template slot-scope="scope">
					<p v-if="scope.row.isInput == '0'">--</p>
					<p v-else >{{scope.row.tipMoney}}</p>
				</template>
			</el-table-column>
			<el-table-column prop="periods" align="center" label="期数" >
			</el-table-column>
			<el-table-column prop="state" align="center" label="状态" width="160">
				<template slot-scope="scope">
					<p v-if="scope.row.state == '0'">待审核</p>
					<p v-if="scope.row.state == '1'">已通过</p>
					<p v-if="scope.row.state == '2'">已拒绝</p>
				</template>
			</el-table-column>
			<el-table-column prop="time" align="center" label="申请时间" width="160" >
			</el-table-column>
			<el-table-column label="操作" width="300" fixed="right">
				<template slot-scope="scope">
					<el-button v-if="scope.row.commissionMoney" type="primary" size="small" icon="el-icon-success" @click="btn(0)">已发放</el-button>
					<el-button v-else-if="scope.row.state == '1' && scope.row.periods == '1'" size="small" type="primary" @click="handleEdit(scope.$index, scope.row)" icon="el-icon-edit">录入</el-button>
					<el-button v-if="scope.row.state == '0'" type="success" size="small" @click="handleReview(scope.$index, scope.row)" icon="el-icon-s-check">通过</el-button>
					<el-button v-else-if="scope.row.state == '1' && !scope.row.commissionMoney" size="small" type="success" icon="el-icon-success" @click="btn(1)">已通过</el-button>
					<el-button v-if="scope.row.state == '0'" size="small" type="danger" @click="handledel(scope.$index, scope.row)" icon="el-icon-delete">拒绝</el-button>
					<el-button v-else-if="scope.row.state == '2'" size="small" type="danger" icon="el-icon-error" @click="btn(2)">已拒绝</el-button>
				</template>
			</el-table-column>
		</el-table>
		<!--批量删除-->
		<el-col :span="24" class="toolbar">
			<el-pagination background layout="total,sizes,prev, pager, next,jumper" @size-change="handleSizeChange" @current-change="handleCurrentChange" :page-size="10" :total="total" style="float:right;">
			</el-pagination>
		</el-col>
		<!-- 编辑 -->
		<el-dialog title="修改费用" :visible.sync="editFormVisible" width="50%" :before-close="handleClose">
			<el-form :model="editForm" label-width="80px" :rules="editFormRules" ref="editForm">
				<el-form-item label="姓名" prop="name">
					<el-input v-model="editForm.name" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="手机号" prop="phone">
					<el-input v-model="editForm.phone" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="所在省" prop="province">
					<el-input v-model="editForm.province" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="所在市" prop="city">
					<el-input v-model="editForm.city" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="手续费" prop="commissionMoney">
					<el-input v-model="editForm.commissionMoney" auto-complete="off"></el-input>
				</el-form-item>
				<el-form-item label="打赏费" prop="tipMoney">
					<el-input v-model="editForm.tipMoney" auto-complete="off"></el-input>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click.native="editFormVisible = false">取消</el-button>
				<el-button type="primary" @click.native="editSubmit" :loading="loading">确定</el-button>
			</div>
		</el-dialog>
	</section>
</template>
<script>
	import util from '../../../common/js/util'
	import {
		getPartner,
		editPartner,
		ReviewPartner,
		Refreshtoken
	} from '../../../api/api';
	
	export default {
		data() {
			return {
				filters: {
					text: ''
				},
				loading: false,
				select: '',
				vid:'',
				UserList: [],
				sels: [],//列表选中列81560
				total: 0,
				page: 1,
				size:10,
				period:0,
				timer: null,
				editFormVisible:false,//弹出层
				// 修改界面数据
				editForm: {
					commissionMoney: '',
					tipMoney: '',
				},
				editFormRules: {
					commissionMoney: [{
						required: true,
						message: '请输入手续费',
						trigger: 'blur'
					}],
					tipMoney: [{
						required: true,
						message: '请输入打赏费',
						trigger: 'blur'
					}]
				},
			}
		},
		mounted() {
			this.getUsersList()
			this.queryInfo();
			this.timer = setInterval(() => {
			   setTimeout(this.queryInfo, 0)
		    }, 600000)
		},
		methods: {
			// 设置定时器
			queryInfo() {
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				let para = {token: Token,timestamp: timestamp};
				Refreshtoken(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
					}
				});
			},
			btn(a){
				if(a == '0'){
					this.$notify({
					  title: '发放成功',
					  message: '手续费和打赏费已发放成功',
					  type: 'success'
					});
				}else if(a=='1'){
					this.$notify({
					  title: '审核成功',
					  message: '该用户已通过城市合伙人的审核',
					  type: 'success'
					});
				}else if(a=='2'){
					this.$notify.error({
					  title: '审核失败',
					  message: '该用户未通过该城市合伙人的审核',
					  type: 'success'
					});
				}
			},
			// 修改角色
			handleEdit(index, row) {
				this.editFormVisible = true;
				this.editForm = Object.assign({}, row);
				//console.log(this.editForm)
			},
			handleClose(done) {
				this.$confirm('确认关闭？')
				    .then(_ => {
						done();
					})
					.catch(_ => {});
			},
			//编辑
			editSubmit: function () {
				this.$refs.editForm.validate((valid) => {
					
					if (valid) {
						this.$confirm('确认提交吗？', '提示', {}).then(() => {
							this.loading = true;
							var Token = sessionStorage.getItem('Token');
							var timestamp = new Date().getTime();
							let para = Object.assign({token: Token, timestamp:timestamp,}, this.editForm);
							editPartner(para).then((res) => {
								this.loading = false;
								this.$message({
									message: '提交成功',
									type: 'success'
								});
								this.$refs['editForm'].resetFields();
								this.editFormVisible = false;
								this.getUsersList();
							});
						});
					}
				});
			},
			
			// 通过审核
			handleReview:function(index, row){
				this.$confirm('是否通过该用户城市合伙人的申请?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(() => {
				  this.$message({
					type: 'success',
					message: '审核通过!'
				  });
				  this.Review(row.userId,row.periods,1)
				}).catch(() => {
				  this.$message({
					type: 'info',
					message: '已取消'
				  });
				});
			},
			// 拒绝审核
			handledel:function(index,row){
				this.$confirm('是否拒绝该用户城市合伙人的申请?', '提示', {
				  confirmButtonText: '确定',
				  cancelButtonText: '取消',
				}).then(() => {
				  this.$message({
					type: 'success',
					message: '拒绝申请提交成功!'
				  });
				  this.Review(row.userId,row.periods,2)
				}).catch(() => {
				  this.$message({
					type: 'info',
					message: '已取消'
				  });
				});
			},
			Review(userId,periods,status){
				console.log(periods)
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				let para = {token: Token,timestamp: timestamp,userId:userId,status:status,periods:periods};
				ReviewPartner(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.loading = false;
						this.getUsersList();
					}
				});
			},
			selsChange: function (sels) {
				this.sels = sels;
			},
			cellStyle({row, column}){
				return 'text-align:center;padding:2px;';
			},
			rowClass({row, column}){
				return 'text-align:center';
			},
			handleSizeChange(val) {
				if(this.filters.text == ''){
					this.size = val;
					this.getUsersList();
				}else{
					this.size = val;
					this.getUsersList(this.filters.text);
				}
			},
			handleCurrentChange(currentPage) {
				this.page = currentPage;
				this.getUsersList();
			},
			//获取用户列表
			getUsersList:function(type){
				var Token = sessionStorage.getItem('Token');
				var timestamp = new Date().getTime();
				if(this.filters.text != ''){
					var para = {token: Token,curpage:this.page,pagesize:this.size,periods:this.filters.text,timestamp: timestamp};	
				}else{
					var para = {token: Token,curpage:this.page,pagesize:this.size,periods:this.period,timestamp: timestamp};	
				}
				
				this.loading = true;
				getPartner(para).then((res) => {
					var res = res.data;
					if (res.code != 0) {
						this.$message({
							message: res.message,
							type: 'error'
						});
					} else {
						this.total = res.data.total;
						this.UserList = res.data.list;
						this.loading = false;
					}
				});
			},
			// 获取用户详情
			handleDetail:function(index, row){
				this.$router.push({
					path:'/userDetail',
					query: {
						mallCode: row.id
					}
				});
			}
		},
		
		beforeDestroy() {
		  clearInterval(this.timer);        
		  this.timer = null;
		}
	};
</script>

<style scoped>
.el-button.is-disabled{
	color: #bfcbd9;
	    cursor: not-allowed;
	    background-image: none;
	    background-color: #eef1f6;
	    border-color: #d1dbe5;
}
.el-pagination {
    white-space: nowrap;
    padding: 2px 5px;
    color: #48576a;
}
.el-select .el-input .el-input--suffix .el-input__inner {
    width: 130px !important;
  }  
</style>
